/**
 * Created by lvzj on 15/10/14.
 */
//轮播图片
function swipter(){
    var mySwiper = new Swiper('.swiper-container', {
        pagination: '.pagination',
        paginationClickable: true
    });
}
$(window).load(function(){
    $('.wrapper').css('padding-top',$('.sharepage-top').height());
});

init();

function init(){
    $('.swiper-wrapper').attr('style', 'height: '+$(document.body).width()+'px;');
    $('.swiper-container').attr('style', 'height: '+$(document.body).width()+'px;');
    $.ajax({
        type: "GET",
        url: serverUrl+'/rest/v1.0/mobile/shares/getGoodsDetail/' + params.goodsId ,
        data: {},
        dataType: "json",
        success: function(data){

            var str = "";
            for (var i = 0; i < data.data.images.length; i++) {
                str += '<div class="swiper-slide" style="height: ' + screen.width + 'px;"><img src="' + data.data.images[i].imageURL + '"> </div>';
            }
            $('.swiper-wrapper').html(str);

            swipter();

            var headImg = data.data.createdBy.images[0].imageURL;
            var nickName = data.data.createdBy.nickName;
            var communityName = data.data.community.communityName;
            var detail = data.data;

            var date = new Date(detail.releaseDate);

            $('#title').html(communityName+"的闲置物品");


            $('#headImg').attr('src',headImg);
            $('#nickName').html(nickName);
            $('.info-top-sub').html(ft(date)+'&nbsp;'+communityName);
            $('#brownerCount').html(detail.browner+'个人看过这个闲置');
            $('#goodsTitle').html(detail.title);
            $('#nowprice').html('¥'+detail.presentPrice);
            $('#preprice').html('<em>原价:</em>'+detail.originalPrice);
            $('.intro').html(detail.desc);
        }
    });

    $.ajax({
        type: "GET",
        url: serverUrl+'/rest/v1.0/mobile/shares/getSharePageGoods',
        data: {},
        dataType: "json",
        success: function(data){
            $('.sale-count').html('小区里面还有<em>'+data.data.count+'</em>个闲置物品正在转让中');
            //
            //var list = data.data.list;
            //var str = "";
            //for(var i = 0 ; i < list.length ; i ++){
            //    str += '<li>';
            //    str += '<a href="javascript:;">';
            //    str += '<img src="'+list[i].pic+'">';
            //    str += '<p class="title">'+list[i].title+'</p>';
            //    str += '<p><span class="nowprice"><em>¥</em>'+list[i].presentPrice+'</span><del class="preprice"><em>原价¥</em>'+list[i].originalPrice+'</del></p>';
            //    str += '</a>';
            //    str += '</li>';
            //}
            //$('#goodsList').html(str);
        }
    });
}
